package edu.upenn.seas.peerreview.pr

import java.security._
import javax.crypto._
import javax.crypto.Cipher._
import com.sun.crypto.provider.SunJCE._

/*
* The cryptography used here is as follows:
* Algorithm: DES (Digital Encryption Standard)
* Mode: ECB (Electronic Codebook Mode)
* Padding: PKCS5Padding 
*/
class Crypto{
  val keyGen: KeyGenerator = KeyGenerator.getInstance("DES")
  keyGen.init(56) //56-bit keys  
  val key: SecretKey = keyGen.generateKey()
  var cEncrypt: Cipher = Cipher.getInstance("DES")
  var cDecrypt: Cipher = Cipher.getInstance("DES")
  var cWrap: Cipher = Cipher.getInstance("DES")
  var cUnwrap: Cipher = Cipher.getInstance("DES")
  cEncrypt.init(ENCRYPT_MODE, key)
  cDecrypt.init(DECRYPT_MODE, key)
  cWrap.init(WRAP_MODE, key)
  cUnwrap.init(UNWRAP_MODE, key)
  
  def encrypt(input: Array[Byte]): Array[Byte]={
    cEncrypt.doFinal(input)
  }
  
  def decrypt(input: Array[Byte]): Array[Byte]={
    cDecrypt.doFinal(input)
  }
}

